package com.uton.rfidcontroller.view.activity;

import com.tencent.bugly.beta.Beta;
import com.uton.rfidcontroller.R;
import com.uton.rfidcontroller.common.intent.IntentBuilder;
import com.uton.rfidcontroller.common.utils.Utils;
import com.uton.rfidcontroller.databinding.ActivityLoginBinding;
import com.uton.rfidcontroller.view.base.BaseActivity;
import com.uton.rfidcontroller.viewmodel.activity_model.LoginActivityViewModel;

import io.reactivex.ObservableTransformer;

/**
 * Created by 王家宝 on 2017/9/20.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginActivityViewModel> {


    @Override
    protected int setLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void inject() {
        getBinding().setModel(getViewModel());
    }

    @Override
    protected String setTitle() {
        return getString(R.string.ui_login);
    }

    @Override
    protected void doSomething() {
        Beta.checkUpgrade();
    }

    @Override
    protected LoginActivityViewModel setViewModel() {
        return new LoginActivityViewModel() {
            @Override
            public void loginSuccess() {
                startActivity(new IntentBuilder().from(LoginActivity.this, MainActivity.class).getIntent());
                finish();
            }

            @Override
            public void loginFailed() {
                Utils.showShortToast(getString(R.string.toast_login_failed));
            }

            @Override
            public void goResetPwd() {
                startActivity(new IntentBuilder().from(LoginActivity.this,ForgetPwdActivity.class).getIntent());
            }

            @Override
            public void showDialog() {
                showProgressDialog(null, false);
            }

            @Override
            public void dismissDialog() {
                disDialog();
            }

            @Override
            public ObservableTransformer setObservable() {
                return compose(bindToLifecycle());
            }
        };
    }
}
